This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Cmd+Shift+Enter.
knitr::read_chunk("prob1.R")
## Save data as data frame Canberra_data and attach the data frame
area <- c(694, 905, 802, 1366, 716, 963, 821, 714, 1018, 887, 790, 696, 771, 1006, 1191)
sale.price <- c(192.0, 215.0, 215.0, 274.0, 112.7, 185.0, 212.0, 220.0, 276.0, 260.0,
221.5, 255.0, 260.0, 293.0, 375.0)
Canberra_data <- data.frame(area,sale.price)
rm(area,sale.price)
head(Canberra_data)
## area sale.price
## 1 694 192.0
## 2 905 215.0
## 3 802 215.0
## 4 1366 274.0
## 5 716 112.7
## 6 963 185.0
attach(Canberra_data)
opar = par(no.readonly=T)
## Create 2x2 grid for plots
par(mfrow=c(2,2))
plot(area,sale.price)
hist(sale.price)
plot(area,log(sale.price))
hist(log(sale.price))
library(plotly)
## Warning: package 'plotly' was built under R version 3.4.1
## Interactive Plots using plotly package. Hover on the plot to get values.
par(opar)
my_plot <- plot_ly( x = ~area, y = ~sale.price, type = 'scatter', mode = 'markers') %>%
layout(
title = "Plot of sale price vs area",
xaxis = list(title = "Area (ha)"),
yaxis = list(title = "Sale Price (x1000 $A)")
)
my_plot
my_plot <- plot_ly(x = sale.price, type = "histogram") %>%
layout(
title = "Histogram for sale price",
xaxis = list(title = "Sale Price"),
yaxis = list(title = "Frequency")
)
my_plot
my_plot <- plot_ly( x = area, y = log(sale.price), type = 'scatter', mode = 'markers') %>%
layout(
title = "Plot of log of sale price vs area",
xaxis = list(title = "Area (ha)"),
yaxis = list(title = "log(Sale Price)")
)
my_plot
my_plot <- plot_ly(x = log(sale.price), type = "histogram") %>%
layout(
title = "Histogram for log of sale price",
xaxis = list(title = "log(Sale Price)"),
yaxis = list(title = "Frequency")
)
my_plot
## Detach data and clear variables.
detach("Canberra_data")
rm(Canberra_data,opar)
<<insertHTML:[test.html]
This is an R HTML document. When you click the Knit HTML button a web page will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
test test